/**
 *    Copyright (C) 2009 Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_CORE_API_METADATA_METADATA_HPP
#define _CUBEFS_CORE_API_METADATA_METADATA_HPP

#include <cubefs/api/metadata/metadata.hpp>
#include <cubefs/core/api/reflection/type.hpp>

#include <cubefs/core/tools/types/traits.hpp>
#include <cubefs/core/tools/types/typelist.hpp>
#include <cubefs/core/tools/types/typemap.hpp>
#include <cubefs/core/tools/bitmap.hpp>


#define CUBEFS_SOURCE "cubefs/core/api/metadata/metadata.hpp:" CUBEFS_AT

namespace cubefs { namespace api {

using cubefs::TypeList;
using cubefs::tools::TypeListTool;
using cubefs::tools::Type2TypeMap;
using cubefs::tools::ValueTraits;

using cubefs::tools::CShr;


template <typename Interface>
class MetadataImplT: public TypedImplT<Interface> {
    typedef MetadataImplT<Interface>		Me;
    typedef TypedImplT<Interface>           Base;

public:

    MetadataImplT(StringRef name, Byte type): name_(name), typeCode_(type) {}

    virtual ~MetadataImplT() throw () {
    	//cout<<"Deleting "<<name_<<endl;
    }

    StringRef Name() const {
        return name_;
    }

    virtual Int GetTypeCode() const {
        return typeCode_;
    }

    static void Init() {
    	AbstractType *type = new AbstractType(TypeNameFactory<Interface>::name(), Typed::MyType());
    	type_ = type;

    	type->AddOperation(new BasicOperation<StringRef (Me::*)(), StringRef (Me::*)() const>(type, "Name", &Me::Name));
    	type->AddOperation(new BasicOperation<Int (Me::*)(), Int (Me::*)() const>(type, "GetTypeCode", &Me::GetTypeCode));
    }

    CUBEFS_DECLARE_REFLECTION;

protected:

    Int &set_type() {
        return typeCode_;
    }

private:
    const String    name_;
    Int             typeCode_;
};

template <typename Interface>
Type* MetadataImplT<Interface>::type_ 					= NULL;

typedef MetadataImplT<Metadata> 						MetadataImpl;



}}

#undef CUBEFS_SOURCE
#endif
